#!/bin/bash

#common
USER_HOME=/home/bes
workspace=/data
JAVA_NAME=jdk1.8.0_261
IP=192.168.3.104
JAVA_HOME=/usr/java/${JAVA_NAME}
USER=bes 
PASSWORD=bes 
JVM=256
METASPACE=64

#DATABASE_TYPE	mysql	magicdata
DATABASE_TYPE=mysql

#source
INSTALL_DIR=/home/bes/onekey
TMP_DIR=${INSTALL_DIR}/tmp

lpwd=`pwd`

function checkenvironment()
{
        echo "####检查环境及用到的软件####"
        listComd="tar zip unzip sed java jar"
        for i in $listComd
        do
		type $i 2>/dev/null >./1.tmp
		if [ -s ./1.tmp ] ; then
			continue;
		else
			echo "$i Commdon is not installded !"
			exit 1;
		fi
        done
        echo "############################"
        rm -f ./1.tmp
        sleep 1
}

function checkworkspace()
{
        echo "####检查安装目录是否存在####"
       	if test -d ${workspace}; then
               	echo "${workspace} exist!";
       	else
               	echo "${workspace} not exist, please create the workspace first and change the owner/group to ${USER} !";
               	exit 1;
       	fi
        sleep 1
        echo "####检查安装目录是否创建启动停止脚本####"
	if test ! -f ${workspace}/start.sh; then
		echo "#!/bin/bash" > ${workspace}/start.sh
		chmod +x ${workspace}/start.sh
	fi
	if test ! -f ${workspace}/stop.sh; then
		echo "#!/bin/bash" > ${workspace}/stop.sh
		chmod +x ${workspace}/stop.sh
	fi
}

function checkdatabase()
{
        echo "检查数据库启动状态..."
        result=ps -ef | grep mysql | grep ${MYSQL_HOME} | grep -v grep | wc -l
        count=`echo $result`
        if [ 0 == ${count} ]; then
                echo ">>>>>> Unable to find ${DATABASE_TYPE} process, please start ${DATABASE_TYPE} first..."
                exit 1;
        fi
	sleep 1
}

source ../config/mysql.cfg
